local BarStatus = require("app.battleV3.ui.objs.BarStatus")
local Head 	  = require("app.battleV3.ui.objs.Head")

local TargetRight = MClass("TargetRight")

local TeamName_Color = cc.c4b(189,255,0, 255)
local EnemyName_Color = cc.c4b(255,1,1, 255)
local Utils = require("app.utils.Util")

--ctor 初始化UI init设置静态数据 setData设置动态数据  updateData更新数据
function TargetRight:ctor()
    --self.root 默认为根节点
    self.name = self:findChild("Panel/Text_2")
    self.head = Head.new(self:findChild("Panel/Panel_head"))
    self.headBoss = Head.new(self:findChild("Panel/Panel_head_boss"))
    self.bar  = BarStatus.new(self:findChild("Panel"))
    self.num = self:findChild("Panel/num")
	self:init()
end

function TargetRight:init()
   self:setVisible(false)
end

function TargetRight:setEnemy(actorType)
	if actorType == Enums.BattleActorType.self or actorType == Enums.BattleActorType.teammate then
		self.name:setTextColor(TeamName_Color)
	else
		self.name:setTextColor(EnemyName_Color)
	end
end

function TargetRight:setData(entityModel,view,targetId)
	self:setVisible(true)
	self.targetId = targetId
	if entityModel:getLv() then
		self.name:setString(string.format("%s lv%d",Utils.getStringInLen(entityModel:getName(),Constant.BATTLE_SHOW_NAME_MAX_LEN),entityModel:getLv()))
	else
		self.name:setString(Utils.getStringInLen(entityModel:getName(),Constant.BATTLE_SHOW_NAME_MAX_LEN))
	end
	self.head:setData(view, entityModel)
	self.bar:setData(view, entityModel)
	self:setEnemy(view:getActorType())
end

function TargetRight:clearData()
	self.bar:clearHideEffect()
end

function TargetRight:updateData(targetId,hpMin,hpMax,manaMin,manaMax,rageMin,rageMax,energyMin,energyMax)
	if targetId ~= self.targetId then return end
	if hpMin <= 0 then
		self:setVisible(false)
	end
	self.bar:updateData(hpMin,hpMax,manaMin,manaMax,rageMin,rageMax,energyMin,energyMax,0,0)
end

function TargetRight:shouldHideAllHpUI(flag)
	self.bar:shouldHideAllHpUI(flag)
end

return TargetRight
